package prototypes;

public class Utilities {
	
	/**
	 * Method to wrap a String at the requested line length.
	 * 
	 * @param length
	 *            the desired line length
	 * @param text
	 *            the text to be split into multiple lines
	 * @return the provided text, split into multiple lines each having the
	 *         length provided (except the last, which will be of length less
	 *         than or equal to the length parameter). Note that the
	 *         aforementioned line length does not include the newline
	 *         character.
	 */
	public static String wrap(int length, String text) {
		
		String output = "";
		int i;
		for (i=0; (i+length)<text.length(); i+=length){
			output += text.substring(i, i+length)+"\n";
		}
		
		if (i < (text.length()-1)){
			output += text.substring(i, text.length())+"\n";
		}
		
		return output;
		
	}

}
